package com.xxxx.skr.implicitTest

/**
 * @program: day0304
 * @description: 尽信书，则不如无书
 * @author: CoreDao
 * @create: 2021-03-04 09:03
 * 隐式转换函数
 * */

class Bird(name:String){
  def fly()={
    println("起飞")
  }
}

class Pig(xname:String){
  val name = xname
}

object ImplicitFun {
  /**
   * 隐式转换函数，让本不能飞的猪也能飞，前提是要能变成鸟
   *
   * 关注参数：谁进来，返回值：谁出去
   */
    implicit def pigToBird(pig: Pig):Bird={
      new Bird(pig.name)
    }

  def main(args: Array[String]): Unit = {
    val bird = new Bird("小鸟")
    bird.fly()

    val pig = new Pig("猪")
    pig.fly()

  }

}
